<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends CommonController {
    public function index(){
     $question=D('verify')->getOneVerify();

     $this->assign('question',$question);

     $this->display();
    }
   

                   public function checkData(){
                   		 // 人类验证
                       $verify = I('post.verify');

                        // 判断人类验证是否正确
                    	if($verify != $_SESSION['answer']){
                    		$arr = array(
                    			'error'=>1,
                    			'info'=>'答案错误'
                    			);
                    		echo json_encode($arr);
                    		exit;
                    	}
                      
                      


                        //判断密码是否一致
                         // var_dump(I('post.pass'));
                    	if($res=D('user')->checkPassword(I('post.email'),I('post.pass'))){
                         
                            $_SESSION['id']=$res['id'];
                            $check=D('user')->find_result();
                           if ($check['del_status']=='1') {
                             $arr = array(
                                'error'=>2,
                                'url'=>U('home/login/index'),
                                'info'=>'账户状态异常，请联系管理员'
                                );
                            echo json_encode($arr);
                            exit;
                               
                           }else{

                            $_SESSION['nickname']=$res['nickname'];
                            $_SESSION['face']=$res['face'];
                             $arr=array(
                                'error'=>0,
                                'info'=>'登陆成功'
                                );
                                echo json_encode($arr);
                                exit;
                            }
                    	}else{
                            $arr = array(
                                'error'=>1,
                                'info'=>'账户或密码不正确'
                                );
                            echo json_encode($arr);
                            exit;
                        }
                		      
                   }


      public function logout(){
            session_unset();
            session_destroy();
            $this->success('退出成功',U('home/index/index'));
       


      }

}